package org.javacore.reflection;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/15.
 * 反射工具类
 */
public class ReflectUtil {
    // 获取某个类clz中有annotaionClass注释的方法
    public static <A extends Annotation> Method[] getAnnotatedMethods(
        Class<?> clz, Class<A> annotaionClass) {

        List<Method> methods = new ArrayList<Method>();
        for (Method method : clz.getMethods()) {
            if (method.getAnnotation(annotaionClass) != null)
                methods.add(method);
        }
        return methods.toArray(new Method[0]);
    }
}
